//
//  XKLTopWindow.m
//  GuiZiShouDuanZi
//
//  Created by xmg on 16/5/9.
//  Copyright © 2016年 xiao_kl. All rights reserved.
//

#import "XKLTopWindow.h"

@implementation XKLTopWindow
static UIWindow * window_;

+(void)initialize{
    UIWindow *window=[[UIWindow alloc] initWithFrame:CGRectMake(0, 0, ScreenW, 20)];
    window_=window;
    window_.windowLevel =UIWindowLevelStatusBar;
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(WindowTap:)];
    [window_ addGestureRecognizer:tap];
}

+(void)show{
    
    window_.hidden=NO;
}
+(void)hidden{
    window_.hidden = YES;
}

//监听点击
+(void)WindowTap:(UITapGestureRecognizer *)tap{
    [self searchScrollView:[UIApplication sharedApplication].keyWindow];
}
+(void)searchScrollView:(UIView *)view{
    for (UIScrollView *scrollView in view.subviews) {
        
        if ([scrollView isKindOfClass:[UIScrollView class]] && scrollView.isShowingOnWindow) {
            
            CGPoint offset = scrollView.contentOffset;
            offset.y = -scrollView.contentInset.top;
            
            [scrollView setContentOffset:offset animated:YES];
            
        }
        
        [self searchScrollView:scrollView];
    }
}
@end
